﻿@model TimeReporting.Models.TimeRecord

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<style>
html
{
    border:0;
    margin:0;
    padding:0;
}
table td
{
    padding-right:10px;
    min-width:200px;
}
fieldset
{
    border:none !important;
}
body
{
    background:none !important;
    border:none !important;
}
</style>

@if (ViewBag.success == null)
{
    using (Html.BeginForm())
    {
    @Html.ValidationSummary(true)
    <fieldset>
        <table>
        <tr>
        <td class="editor-label">
                @Html.LabelFor(model => model.projectID)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.activityID)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.minutes)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.comment)
        </td>
        <td class="editor-label">&nbsp;</td>
        </tr>
        <tr>
        <td class="editor-field">
            <select id="projectID" name="projectID">
            <option value="0">Choose one..</option>
            @foreach (var pId in ViewBag.projectID)
            {
                <option value="@pId.Value">@pId.Text</option>
            }
            </select>
        </td>
        <td class="editor-field">
                <span id="activityIDContainer"><select name="activityID"><option value="">Select Project First</option></select></span>
                @Html.ValidationMessageFor(m => m.activityID)
        </td>
        <td class="editor-field">
                <input name="hr" id="hr" type="text" style="width:30px;" maxlength="2" />&nbsp;<strong>:</strong>&nbsp;<input name="min" id="min" style="width:30px;" type="text" maxlength="2" />
                @Html.TextBoxFor(m => m.minutes)<br />
                @Html.ValidationMessageFor(m => m.minutes)
        </td>
        <td class="editor-field">
                @Html.TextBoxFor(m => m.comment)<br />
                @Html.ValidationMessageFor(m => m.comment)
        </td>
        <td class="editor-field"><input type="submit" value="Submit" name="Index" /></td>
        </tr>
        </table>
    </fieldset>
    }
    <script type="text/javascript">
        $(document).ready(function () {
            $('input#minutes').hide();
            $('input#hr, input#min').change(function () {
                hr = parseInt($("input#hr").val());
                min = parseInt($("input#min").val());
                $('input#minutes').val((hr * 60) + min);
            });
            $("select#projectID").change(function () {
                var pID = $(this).val();
                if (pID != "0") {
                    $.ajax({
                        url: "/TimeRecord/getActivity?pID=" + pID,
                        type: 'GET',
                        success: function (r) {
                            $("span#activityIDContainer").html(r)
                        }
                    });
                }
                else {
                  $("span#activityIDContainer").html('<select name="activityID"><option value="">Select Project First</option></select>');
                }
            });
        });
    </script>

}
else
{
<span>Added Successfully</span>
    <table>
        <tr>
        <td class="editor-label">
                @Html.LabelFor(model => model.projectID)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.activityID)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.minutes)
        </td>
        <td class="editor-label">
                @Html.LabelFor(model => model.comment)
        </td>
        </tr>
        <tr>
        <td class="editor-label">
                @Html.DisplayFor(model => model.projectID)
        </td>
        <td class="editor-label">
                @Html.DisplayFor(model => model.activityID)
        </td>
        <td class="editor-label">
                @Html.DisplayFor(model => model.minutes)
                <span>&nbsp;minutes</span>
        </td>
        <td class="editor-label">
                @Html.DisplayFor(model => model.comment)
        </td>
        </tr>
    </table>
}


         

@*
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th></th>
    </tr>


@foreach (var item in Model) {
    <tr>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
            @Html.ActionLink("Details", "Details", new { id=item.id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.id })
        </td>
    </tr>
}
</table>
*@